<?php
/*
	
*/
defined('BY_JYA') or exit('Access Denied');
global $_RQ,$_AR;
cfc('core')->checklogin();
$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';
$return=array();
$return['diy']=$this->plugin_setting('diy');
$return['setting']=$this->plugin_setting('basic');
if($_RQ['op']=='main' || $_RQ['op']=='wait'){
	$return['params']=array('status'=>intval($_RQ['status']));
	$return['list']=array();
	exi($return);
}
if($_RQ['op']=='list'){
	$params=array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid'],'status'=>intval($_RQ['status']));
	if($_RQ['status']==1){
		$params['status']=array(1,2);
	}
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$total='';
	$list=pdo_getslice('jy_farmer_adopt',$params,array($pindex,$psize),$total,$fields,'','id desc');
	if($list){
		$daytime = mktime(0,0,0,date('m'),date('d'),date('Y'));
		foreach($list as &$item){
			$item['animal']=pdo_get('jy_farmer_animal',array('uniacid'=>$_SESSION['uniacid'],'id'=>$item['animal_id']));
			$item['animal']['atitle']=pdo_getcolumn('jy_farmer_aclassify',array('uniacid'=>$_SESSION['uniacid'],'id'=>$item['animal']['classify_id']),'title');
			$item['animal']['image']=tomedia($item['animal']['image']);
			if($item['number']<10){
				$item['number']='000'.$item['number'];
			}elseif($item['number']<100 && $item['number']>9){
				$item['number']='00'.$item['number'];
			}else{
				$item['number']='0'.$item['number'];
			}
			$item['order']=pdo_get('jy_farmer_order',array('uniacid'=>$_SESSION['uniacid'],'id'=>$item['order_id']),array('address','total','ordersn','money'));
			$totype=pdo_getcolumn('jy_farmer_worker_log',array('createtime >'=>$daytime,'pid'=>$item['id'],'totype'=>4,'type'=>2,'uniacid'=>$_SESSION['uniacid']),'id');
			if($totype){
					$item['totype4']=1;
			}
			$shoudaytime=$item['animal']['growtime']*24*3600+$item['createtime'];
			$item['animal']['shouday']=date('Y-m-d',$shoudaytime);
			if($shoudaytime<time() && ($item['status']==1 ||  $item['status']==2)){
				$item['isshou']=1;
			}
		}
	}
	$return['list']=$list;
	exi($return);
}
if($_RQ['op']=='adopt'){
	if($_RQ['id']){
		pdo_update('jy_farmer_adopt',array('status'=>1),array('uniacid'=>$_SESSION['uniacid'],'id'=>$_RQ['id']));
		exi('将立即通知管理员领养该家禽');
	}else{
		exi('该家禽不存在，请重新选择','error');
	}
	}
if($_RQ['op']=='water'){
	exi('将立即通知管理员前往喂水','error');
	}
if($_RQ['op']=='adopt'){
	exi('将立即通知管理员前往喂食','error');
	}
